<template>
    <!-- 搜索 -->
    <Search @back='goBack'></Search>
    <!-- 顶部导航 -->
    <van-tabs line-width="20px" color="#fa2800" class="up-nav" @click-tab="navTo" v-model:active="active">
        <van-tab line-width=10 v-for="item in NavList" :key="item.order" :title="item.moduleName">
            <RouterView></RouterView>
        </van-tab>
    </van-tabs>
</template>

<script setup lang="ts">
import { getNavList } from '@/api';
import { ref } from 'vue';
import { onMounted } from 'vue';
import Search from '../../components/search/index.vue'
import { useRouter } from 'vue-router'


//导航栏复位（点击图标返回首页时，导航栏复位）
const active = ref(0);
const goBack = () => {
    active.value = 0
}

//导航栏数据
const NavList = ref([])

//导航点击回调
const routes = useRouter()
const route = ref()
routes.getRoutes().map(item => {
    if (item.children && item.children.length && item.path == '/homepage') {
        route.value = item.children
    }
})
const navTo = ({ name }: { name: number }) => {
    routes.push(route.value[name])
}

//初始化数据
const reqNavList = async () => {
    let result = await getNavList()
    NavList.value = result.data

}


onMounted(() => {
    reqNavList()
})
</script>

<style scoped></style>